package com.example.homework3;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.fragment.app.DialogFragment;

public class setCustomItems extends DialogFragment {


    private TextView editTextName1;
    private TextView editTextName2;
    private setCustomItems.NotifyDialogListener listener;

    public interface NotifyDialogListener {
        public void onDialogPositiveClicked(String s, String gender);
    }

    public void setListener(setCustomItems.NotifyDialogListener listener) {
        this.listener = listener;
    }

    //
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater inflater = requireActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.custom_dialog, null);
        editTextName1 =  view.findViewById(R.id.editTextTextPersonName);
        editTextName2 =  view.findViewById(R.id.editTextTextPersonName2);
        builder.setView(view)
                .setTitle("自定义对话框")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(getActivity().getApplicationContext(),"你确定了",Toast.LENGTH_SHORT).show();
                        listener.onDialogPositiveClicked(editTextName1.getText().toString(), editTextName2.getText().toString());
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(getActivity().getApplicationContext(),"你取消了",Toast.LENGTH_SHORT).show();
                        listener.onDialogPositiveClicked(editTextName1.getText().toString(), editTextName2.getText().toString());
                    }
                });
        return builder.create();
    }
}



